/*     */ package btsm.servlet;
/*     */ 
/*     */ import btsm.bean.excelio;
/*     */ import btsm.bean.sqlBTSWork;
/*     */ import btsm.bean.sysPro;
/*     */ import java.io.File;
/*     */ import java.io.IOException;
/*     */ import java.sql.ResultSet;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Arrays;
/*     */ import javax.servlet.RequestDispatcher;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServlet;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.commons.io.FileUtils;
/*     */ 
/*     */ public class ser_btsexport extends HttpServlet
/*     */ {
/*  22 */   private String writeexcel = "";
/*  23 */   private String stexcel = "";
/*     */ 
/*     */   public void init() throws ServletException {
/*  26 */     sysPro sPro = new sysPro();
/*  27 */     this.stexcel = (sPro.getInstalldir() + "stexcel/");
/*  28 */     this.writeexcel = (sPro.getUploadpath() + "writeexcel/");
/*     */   }
/*     */ 
/*     */   public void doGet(HttpServletRequest request, HttpServletResponse response)
/*     */     throws ServletException, IOException
/*     */   {
/*  34 */     excelio EX = new excelio();
/*  35 */     sqlBTSWork SW = new sqlBTSWork("", "");
/*     */ 
/*  37 */     response.setContentType("text/html");
///*  38 */     response.setCharacterEncoding("UTF-8");
/*     */ 
/*  40 */     String msg = ""; String strRDURL = "common.jsp";
/*     */ 
/*  42 */     String seraction = request.getParameter("seraction");
/*  43 */     String strBFilter = request.getParameter("txtFilter");
/*  44 */     String strExpSign = request.getParameter("iExpSign");
/*  45 */     int iExpSign = 100;
/*  46 */     if ((strExpSign != null) && (strExpSign.matches("^[0-9]*$"))) {
/*  47 */       iExpSign = Integer.parseInt(strExpSign);
/*     */     }
/*  49 */     if (seraction == null) {
/*  50 */       seraction = "";
/*     */     }
/*     */ 
/*  53 */     ArrayList excel = new ArrayList();
/*     */ 
/*  55 */     if (seraction.equals("serbtsexport"))
/*     */     {
/*  57 */       int j = 0;
/*  58 */       int jj = 0;
/*     */ 
/*  60 */       if ((this.writeexcel.equalsIgnoreCase("")) || (this.writeexcel == null)) {
/*  61 */         msg = msg + "Excel文件生成目录不能为空";
/*     */       } else {
/*  63 */         File file = new File(this.writeexcel);
/*  64 */         FileUtils.deleteDirectory(file);
/*     */ 
/*  66 */         if (!new File(this.writeexcel).isDirectory()) {
/*  67 */           new File(this.writeexcel).mkdirs();
/*     */         }
/*     */       }
/*     */ 
/*  71 */       if ((this.stexcel.equalsIgnoreCase("")) || (this.stexcel == null)) {
/*  72 */         msg = msg + "Excel模版文件目录不能为空";
/*     */       }
/*     */       else {
/*  75 */         File d = new File(this.stexcel);
/*  76 */         if (d.exists())
/*     */         {
/*  79 */           File[] list = d.listFiles();
/*  80 */           for (int i = 0; i < list.length; i++) {
/*  81 */             j = list[i].getName().length() - list[i].getName().lastIndexOf(".") - 1;
/*  82 */             jj = list[i].getName().length();
/*  83 */             if ((list[i].isFile()) && (list[i].getName().substring(jj - j, jj).equals("xls"))) {
/*  84 */               excel.add(list[i].getName());
/*     */             }
/*     */           }
/*  87 */           if (excel.size() == 0)
/*  88 */             msg = msg + "模版目录没有模版Excel文件！";
/*     */         }
/*     */         else {
/*  91 */           msg = msg + "所设置的Excel模版文件目录不存在！";
/*     */         }
/*     */       }
/*     */ 
/*  95 */       if (msg.equals(""))
/*     */       {
/*  97 */         String[] excela = (String[])excel.toArray(new String[0]);
/*  98 */         Arrays.sort(excela);
/*     */ 
/* 100 */         int[] row = { 5, 2, 4, 4, 3, 2, 3, 2, 2, 3, 2, 3, 3, 3, 2, 3, 2, 2, 3 };
/* 101 */         int[] col = { 48, 10, 41, 9, 30, 11, 10, 12, 8, 9, 11, 23, 14, 21, 9, 14, 11, 13, 13 };
/* 102 */         String[] ve = { "bts_ve", "hunder_ve", "acdc_ve", "tranff_ve", "trans_ve", "montor_ve", "tran_ve", "dynamo_ve", "psupply_ve", "graph_ve", "magn_ve", "ante_ve", "msupply_ve", "mroom_ve", "firee_ve", "pbox_ve", "airc_ve", "sbattery_ve", "itower_ve" };
/* 103 */         SW.idsw = "";
/* 104 */         SW.wheresw = "";
/* 105 */         Boolean result = Boolean.valueOf(true);
/*     */ 
/* 107 */         if (iExpSign > 18)
/* 108 */           for (int i = 0; i < excela.length; i++)
/*     */             try {
/* 110 */               SW.tablesw = ve[i];
/* 111 */               ResultSet rs = SW.sc();
/* 112 */               result = EX.WriteRowCell(this.stexcel + "\\" + excela[i], this.writeexcel + "\\" + excela[i], row[i], col[i], rs);
/*     */             } catch (Exception ex) {
/* 114 */               ex.printStackTrace();
/* 115 */               result = Boolean.valueOf(false);
/*     */             }
/*     */         else {
/*     */           try
/*     */           {
/* 120 */             SW.tablesw = ve[iExpSign];
/*     */             ResultSet rs;
/* 121 */             if ((strBFilter == null) || (strBFilter.equalsIgnoreCase("")))
/* 122 */               rs = SW.sc();
/*     */             else
/* 124 */               rs = SW.BExpQuery(0, strBFilter);
/* 125 */             result = EX.WriteRowCell(this.stexcel + "\\" + excela[iExpSign], this.writeexcel + "\\" + excela[iExpSign], row[iExpSign], col[iExpSign], rs);
/*     */           } catch (Exception ex) {
/* 127 */             ex.printStackTrace();
/* 128 */             result = Boolean.valueOf(false);
/*     */           }
/*     */         }
/*     */ 
/* 132 */         if (result == Boolean.valueOf(true)) {
/* 133 */           msg = msg + "导出Excel文件成功！";
/* 134 */           if (iExpSign > 18)
/* 135 */             strRDURL = "download.jsp";
/*     */           else
/* 137 */             strRDURL = "nnBExpDownload.jsp?iExpSign=" + strExpSign;
/*     */         } else {
/* 139 */           msg = msg + "导出Excel文件失败！";
/*     */         }
/*     */       }
/*     */     }
/* 143 */     request.setAttribute("iEepSign", String.valueOf(iExpSign));
/* 144 */     request.setAttribute("filesnames", "nnBTSExport.jsp");
/* 145 */     request.setAttribute("msg", msg);
/* 146 */     RequestDispatcher btsm = request.getRequestDispatcher(strRDURL);
/* 147 */     btsm.forward(request, response);
/*     */   }
/*     */ 
/*     */   public void doPost(HttpServletRequest request, HttpServletResponse response)
/*     */     throws ServletException, IOException
/*     */   {
/* 153 */     doGet(request, response);
/*     */   }
/*     */ 
/*     */   public void destroy()
/*     */   {
/*     */   }
/*     */ }

/* Location:           E:\java\apache-tomcat-6.0.36\webapps\btsm\WEB-INF\classes\
 * Qualified Name:     btsm.servlet.ser_btsexport
 * JD-Core Version:    0.6.2
 */